#include "tema1.h"
#include <math.h>
#include <iostream>
int x;
Punct::Punct(int xx,int yy){
(*this).x=xx;
(*this).y=yy;
}
void Punct::setX(int xx){
(*this).x=xx;
}
void Punct::setY(int yy){
(*this).y=yy;
}


std::ostream &operator <<(std::ostream& iesire,Punct p){
iesire<<"Punct("<<p.x<<","<<p.y<<")";
return iesire;

}
std::istream &operator >>(std::istream& intrare,Punct &p){

std::cout<<"x=";
intrare>>p.x;
std::cout<<"y=";
intrare>>p.y;
return intrare;
}
double Segment::calculLungime(){
double a,b,s;
a=pow((*this).getA().getX()-(*this).getB().getX(),2.0);
b=pow((*this).getA().getY()-(*this).getB().getY(),2.0);

s=sqrt(a+b);

return s;
}
Punct Segment::getA(){
return (*this).A;
}
Punct Segment::getB(){
return (*this).B;
}
inline double Punct::getX()const{
return (*this).x;
}
inline double Punct::getY()const{
return (*this).y;
}

Segment::Segment(Punct a,Punct b){
(*this).A=a;
(*this).B=b;
}
void Segment::setA(Punct a){
(*this).A=a;
}
void Segment::setB(Punct b){
(*this).B=b;
}
Poligon::Poligon(int n){
std::cout<<"\n Introduceti Punctele:\n";
x=n;
double xx,yy;
for(int i=0;i<n;i++){
	std::cout<<"Introduceti coordonatele punctului "<<i+1;
	std::cout<<"\nx= ";
	std::cin>>xx;
	std::cout<<"y= ";
	std::cin>>yy;
	(*this).puncte[i].setX(xx);
	(*this).puncte[i].setY(yy);
	
	}

}
void Poligon::showPuncte(){
std::cout<<"Punctele sunt: \n";
for(int i=0;i<x;i++){
	std::cout<<"Punctul numarul "<<i+1<<"\n";
	std::cout<<"x= "<<puncte[i].getX();
	std::cout<<"y= "<<puncte[i].getY();
	std::cout<<"\n";
	}
}
bool Poligon::isPoligon(){

if((x>3) && ((*this).puncte[0]==(*this).puncte[x-1]))
	return true;
else
return false;
}
bool Poligon::isTriunghi(){


if  ((*this).isPoligon() && x==4)
	return true;
else
 return false;

}

bool Poligon::isDreptunghi(){
Segment a(puncte[0],puncte[1]);
int aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
int bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
int cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
int dd;
Segment diag1(puncte[0],puncte[2]);
int diagg1;
diagg1=diag1.calculLungime();
Segment diag2(puncte[1],puncte[3]);
int diagg2;
diagg2=diag2.calculLungime();

if ((*this).isPoligon() && diagg1==diagg2 && aa!=bb && aa!=dd)
	return true;
return false;

}
bool Poligon::isSquare(){
Segment a(puncte[0],puncte[1]);
int aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
int bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
int cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
int dd;
dd=d.calculLungime();
Segment diag1(puncte[0],puncte[2]);
int diagg1;
diagg1=diag1.calculLungime();
Segment diag2(puncte[1],puncte[3]);
int diagg2;
diagg2=diag2.calculLungime();
if (((*this).isPoligon() &&diagg1==diagg2&& aa==bb && aa==dd && aa==cc ))
	return true;
return false;

}
bool Punct::operator ==(Punct k){
if ((*this).getX()==k.getX()&&(*this).getY()==k.getY())
	return true;
else return false;
}
bool Punct::operator !=(Punct k){
if ((*this).getX()==k.getX()&&(*this).getY()==k.getY())
	return false;
else return true;
}

bool Poligon::isParalelogram(){
Segment a(puncte[0],puncte[1]);
int aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
int bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
int cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
int dd;
dd=d.calculLungime();
Segment diag1(puncte[0],puncte[2]);
int diagg1;
diagg1=diag1.calculLungime();
Segment diag2(puncte[1],puncte[3]);
int diagg2;
diagg2=diag2.calculLungime();

if ((*this).isPoligon() && diagg1!=diagg2 && aa==cc && bb==dd)
	return true;
return false;

}
bool Poligon::isRomb(){
Segment a(puncte[0],puncte[1]);
int aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
int bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
int cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
int dd;
dd=d.calculLungime();
Segment diag1(puncte[0],puncte[2]);
int diagg1;
diagg1=diag1.calculLungime();
Segment diag2(puncte[1],puncte[3]);
int diagg2;
diagg2=diag2.calculLungime();

if((*this).isParalelogram()&& diagg1!=diagg2&& aa==bb)
return true;
else
return false;
}
double Poligon::aria(){
if(isPoligon()){
if (isDreptunghi())
	{
Segment a(puncte[0],puncte[1]);
double aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
double bb;
bb=b.calculLungime();
double aria;
aria=aa*bb;
return aria;
	}
if(isTriunghi()){
Segment a(puncte[0],puncte[1]);
double aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
double bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
double cc;
cc=c.calculLungime();
double per=aa+bb+cc;
double aria=sqrt(per*(per-aa)*(per-bb)*(per-cc));
return aria;
}
if(isSquare()){
Segment a(puncte[0],puncte[1]);
double aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
double bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
double cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
double dd;
dd=d.calculLungime();
double aria=aa*aa;
return aria;
}	
if (isRomb()){
Segment a(puncte[0],puncte[1]);
double aa;
aa=a.calculLungime();
Segment b(puncte[1],puncte[2]);
double bb;
bb=b.calculLungime();
Segment c(puncte[2],puncte[3]);
double cc;
cc=c.calculLungime();
Segment d(puncte[0],puncte[3]);
double dd;
dd=d.calculLungime();
Segment diag1(puncte[0],puncte[2]);
double diagg1;
diagg1=diag1.calculLungime();
Segment diag2(puncte[1],puncte[3]);
double diagg2;
diagg2=diag2.calculLungime();
double aria=(diagg1+diagg2)/2;
return aria;
}

